package java类及封装;

public class e {
    public static void main(String[] args) {
        e t = new e("李老师");
        t.setAge(30);
        System.out.println(t.getName() + "年龄：" + t.getAge());
    }
    private String name;
    private int age;

    public e(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    // 获取年龄的getter方法
    public int getAge() {
        return age;
    }

    // 设置年龄的setter方法（带合法性校验）
    public void setAge(int age) {
        if (age >= 22 && age <= 65) {
            this.age = age;
        } else {
            System.out.println("年龄不合法（22-65岁）");
        }
    }
}